<?php

namespace App\Controller\Admin;

use App\Controller\InsideService\MailInside;
use App\Middleware\AdminMiddleware;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\GetMapping;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\PostMapping;

#[Controller(prefix: '/admin/Mail'), Middleware(AdminMiddleware::class)]
class MailController extends BaseController {

    #[GetMapping(path: 'index')]
    public function index(): array {
        $userDataArr = $this->uInfo();
        $limit = $this->request->query('size', config('apiadmin.ADMIN_LIST_DEFAULT'));
        $game_hash = $this->request->query('game_hash', '');
        $page = $this->request->query('page', 1);

        if (empty($game_hash)) {
            $game_hash = $userDataArr['user_data']['bind_games'];
        }

        return (new MailInside())->setCode($userDataArr['connection_code'])->index(
            $limit, $game_hash, (int)$page
        );
    }

    #[PostMapping(path: 'add')]
    public function add(): array {
        $userDataArr = $this->uInfo();

        return (new MailInside())->setCode($userDataArr['connection_code'])->add($this->request->post());
    }

    #[GetMapping(path: 'changeStatus')]
    public function changeStatus(): array {
        $id = $this->request->query('id');
        $status = $this->request->query('status');
        $game_hash = $this->request->query('game_hash');
        $userDataArr = $this->uInfo();

        return (new MailInside())->setCode($userDataArr['connection_code'])->changeStatus(
            $id, $status, $game_hash
        );
    }

    /**
     * 获取邮件领取情况列表
     * @return array
     */
    #[GetMapping(path: 'log')]
    public function log(): array {
        $limit = $this->request->query('size', config('apiadmin.admin_list_default'));
        $mail_id = $this->request->query('mail_id', '');
        $openid = $this->request->query('openid', '');
        $game_hash = $this->request->query('game_hash', '');
        $page = $this->request->query('page', 1);
        $userDataArr = $this->uInfo();

        return (new MailInside())->setCode($userDataArr['connection_code'])->log(
            $limit, $mail_id, $openid, $page, $game_hash
        );
    }

    /**
     * 描述:获取玩家邮箱列表
     * 日期: 2023/3/9 17:47
     * @return array
     * @throws \Exception
     * @author: cinder
     */
    #[PostMapping(path: 'getMailInfo')]
    public function getMailInfo(): array {

        $userDataArr = $this->uInfo();

        return (new MailInside())->setCode($userDataArr['connection_code'])->mailList($this->request->post());
    }
}